
import advView from '$v/adv'
import {logoutRequest} from '../api/admin'

export default (req, res, next) => {
  next(advView({
    subRoute: res.subRoute(),
    //给一级目录的ejs传一个url,方便点击时高亮显示
    //点击时路径发生变化,req.url就是当前的路径,传进去后进行判断,如果是当前的路径就加一个active类名
    url: req.url
  }))


  const ologout = document.querySelector('#logout')
  ologout.onclick = async function(){
   try{
    await logoutRequest()
    //退出成功清除token
    localStorage.removeItem('user_token')

    router.go('/login')
    
   }catch(e){
    alert('有异常'+e.message)
   }
  }
}